package com.wego.service.impl;

import com.github.pagehelper.Page;
import com.wego.common.base.impl.BaseServiceImpl;
import com.wego.common.bean.PageBean;
import com.wego.entity.domain.Address;
import com.wego.entity.domain.City;
import com.wego.entity.domain.Country;
import com.wego.entity.domain.Province;
import com.wego.entity.query.AddressQuery;
import com.wego.mapper.CityMapper;
import com.wego.mapper.CountryMapper;
import com.wego.mapper.ProvinceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.wego.mapper.AddressMapper;
import com.wego.service.AddressService;
@Service
public class AddressServiceImpl extends BaseServiceImpl<Address> implements AddressService{

    @Autowired
    private AddressMapper addressMapper;

    @Autowired
    private CountryMapper countryMapper;

    @Autowired
    private CityMapper cityMapper;

    @Autowired
    private ProvinceMapper provinceMapper;

    @Override
    public PageBean<Address> selectPage(AddressQuery addressQuery) {
        //设置分页信息
        Page<Address> page = addressQuery.toPage();
        //查询数据
        addressMapper.selectList(addressQuery);
        //将MyBatis提供的Page对象转换成我们自己的PageBean对象
        return new PageBean<>(page);
    }

    @Override
    public String selectAddress(Long id) {
        Address address = addressMapper.selectByPrimaryKey(id);
        Country country = countryMapper.selectByPrimaryKey(address.getCountryId());
        City city = cityMapper.selectByPrimaryKey(country.getCityId());
        Province province = provinceMapper.selectByPrimaryKey(city.getProvinceId());
        return province.getName() + city.getName() + country.getName() + address.getAddr();
    }
}
